/*
*Copyright 2021-2023 NERCIS
*
*Licensed under the Apache License, Version 2.0 (the "License");
*you may not use this file except in compliance with the License.
*You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*Unless required by applicable law or agreed to in writing, software
*distributed under the License is distributed on an "AS IS" BASIS,
*WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*See the License for the specific language governing permissions and
*limitations under the License.
*/

package cn.ac.nercis.pes.common.constant.evaluation;

import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * 风险等级
 * @author zpy
 * @version 1.0.0
 */
public enum RiskLevel {
    /**空**/
    DEFAULT(0,""),
    HIGH(3,"高"),
    MEDIUM(2,"中"),
    LOW(1,"低");

    private final int level;
    private final String name;

    RiskLevel(int level, String name) {
        this.level = level;
        this.name = name;
    }

    public static RiskLevel fromLevel(Integer level){
        RiskLevel data = DEFAULT;
        for(RiskLevel tt :RiskLevel.values()){
            if(tt.level == level){
                data = tt;
                break;
            }
        }
        return data;
    }

    public static RiskLevel fromName(String name){
        RiskLevel data = DEFAULT;
        for(RiskLevel tt :RiskLevel.values()){
            if(StringUtils.equals(tt.getName(),name)){
                data = tt;
                break;
            }
        }
        return data;
    }

    public static List<RiskLevel> findRiskLevels(){
        return List.of(HIGH,MEDIUM,LOW);
    }


    public int getLevel(){
        return this.level;
    }

    public String getName(){
        return this.name;
    }
}